﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Models;
using System.IO;
namespace Player.ShouYe
{
    public partial class fabu : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btn_fb_Click(object sender, EventArgs e)
        {
            //int id = 5;
            //string title = this.txt_title.Text.Trim();
            //string desc = this.txt_desc.Text.Trim();
            //List<Game> ls = BLL.GameManage.SeleNameLikeGame(title);
            //int gameid = ls[0].Gm_Id;
            ////日期
            //DateTime time = Convert.ToDateTime(DateTime.Now.ToString());
            //Comments com = new Comments();
            //com.Cm_UsId = id;
            //com.Cm_Title = title;
            //com.Cm_GmId = gameid;
            //com.Cm_Desc = desc;
            //com.Cm_Date = time;
            //bool pd = BLL.CommentsManage.AddComments(com);
            //if (pd)
            //{
            //    //发布成功；
            //}

            if (FileUpload.HasFile)
            {
                //获取发布内容
                //用户ID
                int id = 6;
                //游戏名称
                string title = this.txt_title.Text.Trim();
                //获取上传的文件名
                string fileName = FileUpload.FileName;
                //获取上传文件的后缀名
                string fileFix = Path.GetExtension(fileName).ToLower();
                //内容
                string desc = this.txt_desc.Text.Trim();
                if (fileFix == ".png" && fileFix == ".jpeg" && fileFix == ".jpg" && fileFix == ".pic")
                {
                    FileUpload.SaveAs(Server.MapPath(".\\Player\\Player图片\\首页用户发布图片\\" + fileName));
                    this.ImaPic.ImageUrl = "~/Player/首页用户发布图片/" + fileName;
                    //游戏ID
                    List<Game> ls = BLL.GameManage.SeleNameLikeGame(title);
                    int gameid = ls[0].Gm_Id;
                    //日期
                    DateTime time = Convert.ToDateTime(DateTime.Now.ToString());
                    Comments com = new Comments();
                    com.Cm_UsId = id;
                    com.Cm_Title = title;
                    com.Cm_Image = fileName;
                    com.Cm_GmId = gameid;
                    com.Cm_Desc = desc;
                    com.Cm_Date = time;
                    bool pd = BLL.CommentsManage.AddimgComments(com);
                    if (pd)
                    {
                        //发布成功；
                    }
                }
            }
            else
            {
                this.lblMeassge.Text = "抱歉，您上传的不是图片类型上传失败！";
            }
        }
    }
}